namespace Yaaf.WP7.NativeAccess.Helper
{
    using System;

    public class ProvisionXmlRegistry
    {
        private ProvisonXmlBuilder provisonXml;

        private ProvisonXmlCharacteristic rootChar;

        public ProvisionXmlRegistry()
        {
            this.provisonXml = new ProvisonXmlBuilder();
            this.rootChar = new ProvisonXmlCharacteristic() { Type = "Registry" };
            this.provisonXml.AddCharacteristic(rootChar);
        }

        public void AddDeleteKeyOperation(string regKey)
        {
            this.rootChar.AddCharacteristic(new ProvisonXmlCharacteristic(true) { Type = regKey });
        }

        public void AddDeleteValueOperation(string regkey, string valueName)
        {
            var deleteKeyChar = new ProvisonXmlCharacteristic() { Type = regkey, };
            deleteKeyChar.AddParam(new ProvisonXmlParm(true){Name = valueName});
            this.rootChar.AddCharacteristic(deleteKeyChar);
        }

        public void AddSetRegistryKeyOperation(string regKey, string valueName, string value, ProvisionXmlRegistryValueKind valueKind)
        {
            var setKey = new ProvisonXmlCharacteristic() { Type = regKey };
            var kindName = Enum.GetName(typeof(ProvisionXmlRegistryValueKind), valueKind).ToLower();
            setKey.AddParam(new ProvisonXmlParm(){Name = valueName, Value = value, Datatype = kindName});
            this.rootChar.AddCharacteristic(setKey);
        }

        public override string ToString()
        {
            return this.provisonXml.ToString();
        }
    }

    public enum ProvisionXmlRegistryValueKind
    {
        Integer,Boolean,Float,String,

        /// <summary>
        /// Use  &#xF000; to seperate strings and  &#xF000;&#xF000; to end the string collection
        /// </summary>
        Multiplestring,
        
        Binary,
        /// <summary>
        /// time contains the time and time zone. For example "16:55:04-08"
        /// </summary>
        Time,
        /// <summary>
        /// for example "2001-10-20"
        /// </summary>
        Date
    }
}